<template>
  <div class="app">
    <div class="navbar">
      <router-link to="/login" v-if="!userStore.isAuthenticated">登录</router-link>
      <router-link to="/register" v-if="!userStore.isAuthenticated">注册</router-link>
      <button v-else @click="userStore.logout">退出登录</button>
    </div>
    <router-view v-if="userStore.isAuthenticated || $route.path === '/login' || $route.path === '/register'" />
  </div>
</template>

<script setup lang="ts">
import { useUserStore } from './stores/user'
import { onMounted } from 'vue'

const userStore = useUserStore()
onMounted(() => {
  userStore.checkLogin()
})
</script>

<style>
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Arial', sans-serif;
}

.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.navbar {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.navbar a {
  text-decoration: none;
  color: #42b983;
  font-weight: bold;
}

.navbar a:hover {
  text-decoration: underline;
}

.navbar button {
  background: none;
  border: none;
  color: #42b983;
  font-weight: bold;
  cursor: pointer;
  font-size: inherit;
}

.navbar button:hover {
  text-decoration: underline;
}
</style>